#pragma once
#include <cstdint>
#include <string>

class Buffer
{
public:
    Buffer(int32_t size);
    ~Buffer();
    // 扩容
    void extendRoom(int32_t size);
    // 得到剩余的可写的内存容量
    inline int32_t writeableSize()
    {
        return m_capacity - m_writePos;
    }
    // 得到剩余的可读的内存容量
    inline int32_t readableSize()
    {
        return m_writePos - m_readPos;
    }
    //得到读数据的起始位置
    inline char *data()
    {
        return m_data + m_readPos;
    }
    inline int readPosIncrease(int count)
    {
        m_readPos += count;
        return m_readPos;
    }

    // 写内存 1.直接写 2.接收套接字数据
    int8_t appendData(const char *data, int32_t size);
    int8_t appendString(const char *data);
    int8_t appendString(const std::string data);
    int32_t socketRead(int32_t fd);
    // 根据\r\n取出一行，找到其在数据块中的位置，返回该位置
    char *findCRLF();
    int32_t sendData(int32_t socket);


private:
    // 指向内存的指针
    char *m_data;
    int32_t m_capacity;
    int32_t m_readPos = 0;
    int32_t m_writePos = 0;
};
